<?php require_once(dirname (__FILE__) . '/meta-boxes.php') ?>
<div class="wrap">
	<?php screen_icon( 'wvcf' ); ?>
	<h2>
		<?php _e("Custom Field Categories") ?> 
		<a href="<?php echo admin_url('admin.php?page=wvcf-add') ?>" class="button add-new-h2">Add New</a>
	</h2>
	
	<?php if ( $notice ) : ?>
		<div id="notice" class="error"><p><?php echo $notice ?></p></div>
	<?php endif; ?>
	<?php if ( $message ) : ?>
		<div id="message" class="updated"><p><?php echo $message; ?></p></div>
	<?php endif; ?>
	
	<form action="admin.php?page=wvcf" id="category-filter" method="post" accept-charset="utf-8">
		
		<?php if ($categories): ?>
		
		<div class="tablenav">
			<div class="alignleft actions">
				<select name="bulkaction" id="bulkaction">
					<option value="no_action" ><?php _e("No Action",'wv'); ?></option>
					<option value="delete" ><?php _e("Delete Permanently",'wv'); ?></option>
				</select>
				<input class="button-secondary" type="button" id="actions-apply" value="<?php _e('Apply','wv'); ?>" />
				<span id="ajax-message" class="hidden"></span>
			</div>
			
			<?php if ( $page_links ) : ?>
			<div class="tablenav-pages">
			<?php 
				$page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
					number_format_i18n( ( $paged - 1 ) * $wvdb->paged['objects_per_page'] + 1 ),
					number_format_i18n( min( $paged * $wvdb->paged['objects_per_page'], $wvdb->paged['total_objects'] ) ),
					number_format_i18n( $wvdb->paged['total_objects'] ),
					$page_links
				); 
				echo $page_links_text; ?>
			</div>
			<?php endif; ?>
		</div>
		
		<table class="widefat" cellspacing="0">
			<thead>
				<tr>
					<th scope="col" class="manage-column column-cb check-column">
						<input type="checkbox" onclick="checkAll(document.getElementById('categories-filter'));" name="checkall"/>
					</th>
					<th scope="col" class='manage-column column-title'><?php _e('Name', 'wv'); ?></a></th>
					<th scope="col" class='manage-column column-author'><?php _e('Type', 'wv'); ?></th>
					<th scope="col" class="manage-column column-comments" id="comments" scope="col"><?php _e('Always Show?', 'wv'); ?></th>
					<th scope="col" class='manage-column column-tags'><?php _e('Actions', 'wv'); ?></th>
				</tr>
			</thead>
			<tfoot>
				<tr>
					<th scope="col" class="manage-column column-cb check-column">
						<input type="checkbox" onclick="checkAll(document.getElementById('categories-filter'));" name="checkall"/>
					</th>
					<th scope="col" class='manage-column column-title'><?php _e('Name', 'wv'); ?></a></th>
					<th scope="col" class='manage-column column-author'><?php _e('Type', 'wv'); ?></th>
					<th scope="col" class="manage-column column-comments" id="comments" scope="col"><?php _e('Always Show?', 'wv'); ?></th>
					<th scope="col" class='manage-column column-tags'><?php _e('Actions', 'wv'); ?></th>
				</tr>
			</tfoot>            
			<tbody>
				<?php 
				$class = 'class="odd"';
				foreach ((array)$categories as $cat): 
					
					$class = empty($class) ? 'class="odd"' : '';
					$cat->always_show = intval($cat->always_show);
					$yn = array(0 => 'No', 1 => 'Yes');
				?>
				
				<tr id="category-<?php echo $cat->cat_id ?>" <?php echo $class; ?> >		
					<th scope="row" class="cb column-cb check-column">
						<input name="doaction[]" type="checkbox" value="<?php echo $cat->cat_id ?>" />
					</th>
					<td class='post-title column-title'>
						<strong>
							<a class='row-title' href="<?php echo wp_nonce_url( 'admin.php?page=wvcf&mode=edit&cid=' . $cat->cat_id, 'wvcf_manage')?>" class='edit' title="<?php _e('Edit') ?>" > <?php echo esc_html($cat->name) ?> </a>
						</strong>
					</td>
					<td><?php echo get_type_label($cat->type) ?></td>
					<td><?php echo $yn[$cat->always_show] ?></td>
					<td class="row-action">
							<span class="edit"><a title="Edit this item" href="<?php echo wp_nonce_url( 'admin.php?page=wvcf&mode=edit&cid=' . $cat->cat_id, 'wvcf_manage')?>"><?php _e('Edit') ?></a> | </span>
							<span class="trash"><strong><a href="#delete-<?php echo $cat->cat_id ?>" title="Delete this category" class="delete"><?php _e('Delete') ?></a></strong> </span>
					</td>
				</tr>
				<?php endforeach ?>
			</tbody>
		</table>
		
		<div class="tablenav">
			<div class="alignleft actions">
		
			</div>
			
			<?php if ( $page_links ) : ?>
			<div class="tablenav-pages">
			<?php 
				$page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
					number_format_i18n( ( $paged - 1 ) * $wvdb->paged['objects_per_page'] + 1 ),
					number_format_i18n( min( $paged * $wvdb->paged['objects_per_page'], $wvdb->paged['total_objects'] ) ),
					number_format_i18n( $wvdb->paged['total_objects'] ),
					$page_links
				); 
				echo $page_links_text; ?>
			</div>
			<?php endif; ?>
			
		</div>
		
		<?php else: // $categories ?> 
		<?php _e('No categories found.') ?>
		<?php endif ?>
		
	</form>
	
</div>

